package com.mhs.dataclassification.processTS;

import java.util.Date;

import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;

import com.mhs.DTO.MySQLiteHelper;

public class ProcessTS_ThuocDTO {
	
	public static void updateTS_ThuocDTO_Select(int id_MaThuoc, SQLiteDatabase database, MySQLiteHelper dbHelper){
		database = dbHelper.getWritableDatabase();
		String sQueryFirst = "select TS from thuoc where mathuocclient = " + id_MaThuoc + ";";
		Cursor cursor = database.rawQuery(sQueryFirst, new String [] {});
		if(cursor.getCount() == 0){
			return;
		}else if(cursor.getCount() == 1){
			Long TS_New = getCurrentTime();
			String sQuery = "update thuoc set TS = " + TS_New.toString() + " where mathuocclient = " + id_MaThuoc + ";";		
			database.execSQL(sQuery);
		}
	}
	
	public static Long getCurrentTime(){
		return new Long(new Date().getTime());
	}
	
	public static Long getTS_ThuocDTO(int id_MaThuoc, SQLiteDatabase database, MySQLiteHelper dbHelper){
		database = dbHelper.getWritableDatabase();
		Long TS = null;
		String sQuery = "select TS from thuoc where mathuocclient = " + id_MaThuoc + ";";
		Cursor cursor = database.rawQuery(sQuery, new String [] {});
		if(cursor.getCount() == 0){
			TS = null;
		}else if(cursor.getCount() == 1){
			TS = new Long(cursor.getString(0));
		}
		return TS;
	}
}
